package com.team.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.team.dao.NoticeMapper;
import com.team.entity.Notice;
import com.team.service.NoticeService;
import com.team.vo.NoticeVo;
import com.team.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author : 陈灰灰
 * @Date: 2022/10/18/10:14
 * @Description:
 */
@Service
public class NoticeServiceImpl implements NoticeService {
    @Autowired
    private NoticeMapper noticeMapper;
    @Override
    public Result queryAllNotice(int currentPage, int pageSize, NoticeVo noticeVo) {
        if(noticeVo.getDate()!=null){
            noticeVo.setStartDate(noticeVo.getDate()[0]);
            noticeVo.setEndDate(noticeVo.getDate()[1]);
        }
        PageHelper.startPage(currentPage,pageSize);
        List<Notice> notices = noticeMapper.selectAllNotice(noticeVo);
        PageInfo<Notice> pageInfo = new PageInfo<>(notices);
        return new Result(200,"查询成功",pageInfo);
    }

    @Override
    public Result deleteById(int id) {
        noticeMapper.deleteByPrimaryKey(id);
        return new Result(200,"删除成功");
    }

    @Override
    public Result updateNotice(Notice notice) {
        noticeMapper.updateByPrimaryKeySelective(notice);
        return new Result(200,"修改成功");
    }

    @Override
    public Result addNotice(Notice notice) {
        noticeMapper.insertSelective(notice);
        return new Result(200,"添加成功");
    }
}
